﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.System.Validator;
using Shpm.System.Web.Control;
using log4net;
using Shpm.App.Input.Bean;
using Shpm.App.Input.Dao;
using Shpm.App.Commons.Db.Beans.Master;
using Shpm.System;
using Shpm.App.Commons.Utils;
using System.Text.RegularExpressions;

public partial class App_Input_HappyPlanResultForm : System.Web.UI.Page
{
    // log
    protected static ILog log = LogManager.GetLogger(typeof(App_Input_HappyPlanResultForm));

    protected string docContentHtml = string.Empty;
    protected const string ACTION_TYPE = "C";

    // page load
    protected void Page_Load(object sender, EventArgs e)
    {
        //txtActMainPsn.Attributes.Add("onchange", "showEmployeeName(this.id,'" + txtActMainPsnName.ClientID + "');");
        txtActMainPsn.Attributes.Add("onblur", "showEmployeeName(this.id,'" + txtActMainPsnName.ClientID + "');");
        //  txtActMainPsnName.Attributes.Add("onfocus", "document.getElementById('" + txtActMainPsn.ClientID + "').focus();");

        txtActCoPsn1.Attributes.Add("onblur", "showEmployeeName(this.id,'" + txtActCoPsn1Name.ClientID + "');");
        //  txtActCoPsn1Name.Attributes.Add("onfocus", "document.getElementById('" + txtActCoPsn1.ClientID + "').focus();");
        txtActCoPsn2.Attributes.Add("onblur", "showEmployeeName(this.id,'" + txtActCoPsn2Name.ClientID + "');");
        //  txtActCoPsn2Name.Attributes.Add("onfocus", "document.getElementById('" + txtActCoPsn2.ClientID + "').focus();");
        txtActCoPsn3.Attributes.Add("onblur", "showEmployeeName(this.id,'" + txtActCoPsn3Name.ClientID + "');");
        //  txtActCoPsn3Name.Attributes.Add("onfocus", "document.getElementById('" + txtActCoPsn3.ClientID + "').focus();");

        if (!Page.IsPostBack)
        {
            ViewState["ACTION_TYPE"] = Context.Items["ACTION_TYPE"];
            // 保存接收的参数
            ViewState["InpActName"] = Convert.ToString(Context.Items["InpActName"]);
            ViewState["InpActType"] = Convert.ToString(Context.Items["InpActType"]);
            ViewState["InpActStat1"] = Convert.ToString(Context.Items["InpActStat1"]);
            ViewState["InpActStat2"] = Convert.ToString(Context.Items["InpActStat2"]);
            ViewState["InpBeginDate"] = Convert.ToString(Context.Items["InpBeginDate"]);
            ViewState["InpEndDate"] = Convert.ToString(Context.Items["InpEndDate"]);

            ViewState["HidActName"] = Convert.ToString(Context.Items["HidActName"]);
            ViewState["HidActType"] = Convert.ToString(Context.Items["HidActType"]);
            ViewState["HidActStat1"] = Convert.ToString(Context.Items["HidActStat1"]);
            ViewState["HidActStat2"] = Convert.ToString(Context.Items["HidActStat2"]);
            ViewState["HidBeginDate"] = Convert.ToString(Context.Items["HidBeginDate"]);
            ViewState["HidEndDate"] = Convert.ToString(Context.Items["HidEndDate"]);
            ViewState["HidCommand"] = Convert.ToString(Context.Items["HidCommand"]);

            if (Context.Items.Contains("HidPageIndex"))
            {
                ViewState["HidPageIndex"] = Context.Items["HidPageIndex"];
            }

            // init page
            ViewState["MODE"] = "";
            if (Context.Items.Contains("MODE"))
            {
                ViewState["MODE"] = Context.Items["MODE"];
            }

            // 活动编号
           // ViewState["ACTION_ID"] = Convert.ToString(Context.Items["ACTION_ID"]);
            ViewState["ACTION_ID"] = Convert.ToString(Context.Items["ACTION_ID"]);
            // 初始化控件
            initPageControls();

           

            // get data
            if (!string.IsNullOrEmpty(Convert.ToString(ViewState["ACTION_ID"])))
            {
                this.lstActType.Enabled = false;
                bindSelectData(Convert.ToString(ViewState["ACTION_ID"]));
            }
            else 
            {
                this.lstActType.Enabled = true;
                btnDel.Enabled = false;
            }
            

        }
        else
        {
            //string htmlDoc = Convert.ToString(Request.Form["FCKeditor1"]);
            //if (htmlDoc == null) htmlDoc = "";
            //htmlDoc = Regex.Replace(htmlDoc, "\\n|\\r|\\t|\\v", ""); //^\s*|\s*$
            ////this.ViewState["HTML_DOC"] = htmlDoc;
            //this.docContentHtml = Regex.Replace(htmlDoc, "'", "\\'");
        }
    }

    // 保存按钮
    protected void btnOk_Click(object sender, EventArgs e)
    {
        try
        {
            // do validate check
            // page 
            ComValidateChecker vd = new ComValidateChecker();
            vd.CheckItems.Add(new CheckRequired(txtActName.Text, new ComMessage("E0094", "活动名称")));
            vd.CheckItems.Add(new CheckRequired(lstActType.Text, new ComMessage("E0094", "活动分类")));
            vd.CheckItems.Add(new CheckRequired(txtActDate.Text, new ComMessage("E0094", "活动日期")));
            vd.CheckItems.Add(new CheckRequired(txtActAddress.Text, new ComMessage("E0094", "活动地点")));
            vd.CheckItems.Add(new CheckRequired(txtActMainPsn.Text, new ComMessage("E0094", "责任人")));

            vd.CheckItems.Add(new CheckLong(txtActCount.Text, new ComMessage("E0322", "预计人数")));
            vd.CheckItems.Add(new CheckDate(txtActDate.Text, "yyyy/MM/dd", new ComMessage("E0037", "活动日期")));

           // vd.CheckItems.Add(new CheckDateRange(DateUtils.convertToString(DateTime.Now), txtActDate.Text, "yyyy/MM/dd", new ComMessage("E0329", new string[] { "当前日期", "活动日期" })));
            vd.CheckItems.Add(new CheckDouble(txtFeePropagandize.Text, 7, 2, new ComMessage("E0064", new string[] { "宣传费用", "7", "2" })));
            vd.CheckItems.Add(new CheckDouble(txtFeeManpower.Text, 7, 2, new ComMessage("E0064", new string[] { "人工费用", "7", "2" })));
            vd.CheckItems.Add(new CheckDouble(txtFeeMaterial.Text, 7, 2, new ComMessage("E0064", new string[] { "材料费用", "7", "2" })));
            vd.CheckItems.Add(new CheckDouble(txtFeeTraffic.Text, 7, 2, new ComMessage("E0064", new string[] { "交通费用", "7", "2" })));
            vd.CheckItems.Add(new CheckDouble(txtFeeOther.Text, 7, 2, new ComMessage("E0064", new string[] { "其他费用", "7", "2" })));
            vd.CheckItems.Add(new CheckDouble(txtFeeTotal.Text, 7, 2, new ComMessage("E0064", new string[] { "合计费用", "8", "2" })));

            if (ACTION_TYPE.Equals(Convert.ToString(ViewState["ACTION_TYPE"])))
            {
                vd.CheckItems.Add(new CheckRequired(txtVolunteerNum.Text, new ComMessage("E0094", "义工人数")));
                vd.CheckItems.Add(new CheckRequired(txtServerNum.Text, new ComMessage("E0094", "服务人数")));
                vd.CheckItems.Add(new CheckLong(this.txtServerNum.Text, new ComMessage("E0322", "服务人数")));
                vd.CheckItems.Add(new CheckLong(this.txtVolunteerNum.Text, new ComMessage("E0322", "义工人数")));
              //  vd.CheckItems.Add(new CheckDateRange(DateUtils.convertToString(DateTime.Now), txtActDate.Text, "yyyy/MM/dd", new ComMessage("E0329", new string[] { "当前日期", "活动日期" })));
            }
            if (!vd.DoValidator())
            {
                ((Design_MasterPage)this.Master).InfoMessage = vd.ErrorMessage;
                return;
            }

            // person exist
            if (!checkExistPerson(txtActMainPsn.Text))
            {
                ((Design_MasterPage)this.Master).InfoMessage =
                    HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "E0203").ToString().Replace("{0}", "责任人");
                return;
            }

            if (!string.IsNullOrEmpty(txtActCoPsn1.Text)
                && !checkExistPerson(txtActCoPsn1.Text))
            {
                ((Design_MasterPage)this.Master).InfoMessage =
                    HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "E0203").ToString().Replace("{0}", "协助人1");
                return;
            }
            if (!string.IsNullOrEmpty(txtActCoPsn2.Text)
                && !checkExistPerson(txtActCoPsn2.Text))
            {
                ((Design_MasterPage)this.Master).InfoMessage =
                    HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "E0203").ToString().Replace("{0}", "协助人2");
                return;
            }
            if (!string.IsNullOrEmpty(txtActCoPsn3.Text)
                 && !checkExistPerson(txtActCoPsn3.Text))
            {
                ((Design_MasterPage)this.Master).InfoMessage =
                    HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "E0203").ToString().Replace("{0}", "协助人3");
                return;
            }

            // insert update
            insertUpdate();
            btnDel.Enabled = true;

        }
        catch (Exception ex)
        {
            log.Fatal(ex.StackTrace);
            log.Fatal(ex.Message);
           // throw ex;
        }
    }

    // 删除按钮
    protected void btnDel_Click(object sender, EventArgs e)
    {
        try
        {

            HappyPlanResultDao dao = new HappyPlanResultDao();
            HappyPlanResultBean bean = new HappyPlanResultBean();
            if (!string.IsNullOrEmpty(this.lblActId.Text))
            {
                bean.ActionResultId = Convert.ToInt32(this.lblActId.Text);
                bean = dao.LoadHappyPlanResultByResultId(bean);
                if (bean == null)
                {
                    ((Design_MasterPage)this.Master).InfoMessage =
                        HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "E0203").ToString().Replace("{0}", "活动计划");
                    return;
                }
                int delCnt = dao.Delete(bean);
                // clear form
                resetFormControls();
                btnDel.Enabled = false;
                ((Design_MasterPage)this.Master).InfoMessage =
                    HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "I0003").ToString();
            }
        }
        catch (Exception ex)
        {
            log.Fatal(ex.StackTrace);
            log.Fatal(ex.Message);
            throw ex;
        }
    }

    // 审核按钮
   

    // 返回按钮
    protected void btnBack_Click(object sender, EventArgs e)
    {
        string url = "~/App/Input/VolunteerSrhForm.aspx";

        // 回传接收的参数       
        //Context.Items["InpActName"] = ViewState["InpActName"];
        //Context.Items["InpActType"] = ViewState["InpActType"];
        //Context.Items["InpActStat1"] = ViewState["InpActStat1"];
        //Context.Items["InpActStat2"] = ViewState["InpActStat2"];
        //Context.Items["InpBeginDate"] = ViewState["InpBeginDate"];
        //Context.Items["InpEndDate"] = ViewState["InpEndDate"];

        //Context.Items["HidActName"] = ViewState["HidActName"];
        //Context.Items["HidActType"] = ViewState["HidActType"];
        //Context.Items["HidActStat1"] = ViewState["HidActStat1"];
        //Context.Items["HidActStat2"] = ViewState["HidActStat2"];
        //Context.Items["HidBeginDate"] = ViewState["HidBeginDate"];
        //Context.Items["HidEndDate"] = ViewState["HidEndDate"];
        //Context.Items["HidCommand"] = ViewState["HidCommand"];
        //Context.Items["HidPageIndex"] = ViewState["HidPageIndex"];


        ControllerUtils.Transfer(Context, url, true);
    }

    // check auditing person authority(审核人权限check)
    private Boolean checkAuditingAuthority(string actionId)
    {
        // get employee info
        SysUserManager manager = new SysUserManager(Context);
        SysUserBean sysUserBean = manager.getSysUserBean();
        MstSysUserBean mstSysUserBean =
            sysUserBean == null ? null : sysUserBean.getMstSysUserBean();
        MstEmployeeBean mstEmpBean =
            sysUserBean == null ? null : sysUserBean.getEmployeeBean();
        string loginId = mstSysUserBean == null ? "" : mstSysUserBean.SysUserId;
        string emplyId = mstSysUserBean == null ? "" : mstSysUserBean.EmployeeId;


        HappyPlanDao dao = new HappyPlanDao();
        HappyPlanBean bean = new HappyPlanBean();
        bean.ActionId = Convert.ToInt32(actionId);
        bean = dao.FindHappyPlan(bean);
        if (bean == null
            || getJobLevel() < 1)
        {
            ((Design_MasterPage)this.Master).InfoMessage =
                HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "E0901").ToString();
            return false;
        }

        // 是否已经审批通过
        if (bean.AuditingFlg != null && bean.AuditingFlg.Value)
        {
            ((Design_MasterPage)this.Master).InfoMessage =
                HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "I0029").ToString().Replace("{0}", "已经审批");
            return false;
        }

        // 是否已经提交
        if (bean.CommitFlg == null
            || (bean.CommitFlg != null && !bean.CommitFlg.Value))
        {
            ((Design_MasterPage)this.Master).InfoMessage =
                HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "I0036").ToString().Replace("{0}", "还未提交");
            return false;
        }

        return true;
    }

    // check person exist
    private Boolean checkExistPerson(string empId)
    {
        HappyPlanDao dao = new HappyPlanDao();
        PersonEmployeeBean beanME = new PersonEmployeeBean();
        beanME.EmployeeId = empId;
        beanME = dao.GetEmployee(beanME);
        if (beanME == null)
        { return false; }

        return true;
    }

    // check authority for update（更新人 登记人 是否同一人） 
    private Boolean checkUpdateAuthority(string actionId)
    {
        if (string.IsNullOrEmpty(actionId))
        {
            ((Design_MasterPage)this.Master).InfoMessage =
                HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "E0901").ToString();
            return false;
        }

        SysUserManager manager = new SysUserManager(Context);
        SysUserBean sysUserBean = manager.getSysUserBean();
        MstSysUserBean mstSysUserBean =
            sysUserBean == null ? null : sysUserBean.getMstSysUserBean();
        MstEmployeeBean mstEmpBean =
            sysUserBean == null ? null : sysUserBean.getEmployeeBean();
        string loginId = mstSysUserBean == null ? "" : mstSysUserBean.SysUserId;
        string emplyId = mstSysUserBean == null ? "" : mstSysUserBean.EmployeeId;

        HappyPlanDao dao = new HappyPlanDao();
        HappyPlanBean bean = new HappyPlanBean();
        bean.ActionId = Convert.ToInt32(actionId);
        bean = dao.FindHappyPlan(bean);
        if (bean == null
            || string.IsNullOrEmpty(bean.EmployeeId)
            || !emplyId.Equals(bean.EmployeeId))
        {
            ((Design_MasterPage)this.Master).InfoMessage =
                HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "E0901").ToString();
            return false;
        }

        // 是否已经审批通过
        if (!"0".Equals(bean.DepartmentAdvice)
            || !"0".Equals(bean.ManagerAdvice))
        {
            ((Design_MasterPage)this.Master).InfoMessage =
                HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "I0029").ToString().Replace("{0}", "上级已经审批");
            return false;
        }

        // 是否已经提交
        if (bean.CommitFlg != null && bean.CommitFlg.Value)
        {
            ((Design_MasterPage)this.Master).InfoMessage =
                HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "I0036").ToString().Replace("{0}", "已经提交");
            return false;
        }

        return true;
    }

    // 插入 更新 数据 
    private void insertUpdate()
    {
        string retKey = string.Empty;

        SysUserManager manager = new SysUserManager(Context);
        SysUserBean sysUserBean = manager.getSysUserBean();
        MstSysUserBean mstSysUserBean =
            sysUserBean == null ? null : sysUserBean.getMstSysUserBean();
        MstEmployeeBean mstEmpBean =
            sysUserBean == null ? null : sysUserBean.getEmployeeBean();
        string loginId = mstSysUserBean == null ? "" : mstSysUserBean.SysUserId;
        string emplyId = mstSysUserBean == null ? "" : mstSysUserBean.EmployeeId;

        // get date from page
        HappyPlanResultDao dao = new HappyPlanResultDao();
        HappyPlanResultBean bean = new HappyPlanResultBean();
        bean.ActionName = txtActName.Text;
        bean.ActionType = lstActType.SelectedValue;
        if (!string.IsNullOrEmpty(txtActDate.Text))
        { bean.BespokeDate = DateUtils.convertToDate(txtActDate.Text); }
        bean.BespokeDateText = txtActDateMemo.Text;
        bean.ActionAddress = txtActAddress.Text;
        bean.ActionObject = txtActObject.Text;
        if (!string.IsNullOrEmpty(txtActCount.Text))
        { bean.ActionCount = Convert.ToInt32(txtActCount.Text); }
        bean.ResponsibilityId = txtActMainPsn.Text;
        if (!string.IsNullOrEmpty(txtActCoPsn1.Text))
        { bean.CoadjutantId = txtActCoPsn1.Text; }
        if (!string.IsNullOrEmpty(txtActCoPsn2.Text))
        { bean.Coadjutant2Id = txtActCoPsn2.Text; }
        if (!string.IsNullOrEmpty(txtActCoPsn3.Text))
        { bean.Coadjutant3Id = txtActCoPsn3.Text; }

        // fee
        if (!string.IsNullOrEmpty(txtFeePropagandize.Text))
        { bean.FeePropagandize = Convert.ToDecimal(txtFeePropagandize.Text); }
        if (!string.IsNullOrEmpty(txtFeeManpower.Text))
        { bean.FeeManpower = Convert.ToDecimal(txtFeeManpower.Text); }
        if (!string.IsNullOrEmpty(txtFeeMaterial.Text))
        { bean.FeeMaterial = Convert.ToDecimal(txtFeeMaterial.Text); }
        if (!string.IsNullOrEmpty(txtFeeTraffic.Text))
        { bean.FeeTraffic = Convert.ToDecimal(txtFeeTraffic.Text); }
        if (!string.IsNullOrEmpty(txtFeeOther.Text))
        { bean.FeeOther = Convert.ToDecimal(txtFeeOther.Text); }
     

        if (ACTION_TYPE.Equals(Convert.ToString(ViewState["ACTION_TYPE"])))
        {
            bean.VolunteerNum = Convert.ToInt32(this.txtVolunteerNum.Text);
            bean.ServerNum = Convert.ToInt32(this.txtServerNum.Text);
            bean.ServerType = this.radServerType.SelectedValue;
            bean.ServerOther = this.radServerType.SelectedIndex == 3?this.txtServerOther.Text:"";
        }

        bean.ActionContent = this.txtContent.Text;

        bean.ActionDocument = txtMemo2.Text;

        bean.UserId = loginId;
        bean.EmployeeId = emplyId;
        bean.DepartmentAdvice = "0";
        bean.ManagerAdvice = "0";
        bean.CommitFlg = false;

        bean.AuditingFlg = false;
        bean.CompleteFlg = false;
        bean.EmployeeId = emplyId;
        if (string.IsNullOrEmpty(this.lblActId.Text))
        {
            // new plan insert
            if (!string.IsNullOrEmpty(Convert.ToString(ViewState["ACTION_ID"])))
            bean.ActionId = Convert.ToInt32(ViewState["ACTION_ID"]);
            int actionId = (int)dao.Insert(bean);
            this.lblActId.Text = actionId.ToString();
            ((Design_MasterPage)this.Master).InfoMessage =
                HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "I0001").ToString();
        }
        else
        {

            bean.ActionResultId = Convert.ToInt32(this.lblActId.Text);

            dao.Update(bean);
            ((Design_MasterPage)this.Master).InfoMessage =
                HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "I0002").ToString();
        }

    }

    // bind data to controls
    private void bindSelectData(string id)
    {
      // 编辑 活动计划
        // 读取 活动计划数据
        HappyPlanResultDao dao = new HappyPlanResultDao();
        HappyPlanResultBean bean = new HappyPlanResultBean();
        //义工活动
        bean.ActionResultId = Convert.ToInt32(id);
        bean = dao.LoadHappyPlanResultByResultId(bean);

        this.lstActType.SelectedValue = bean.ActionType;
        //显示义工活动控件
        if (ACTION_TYPE.Equals(Convert.ToString(bean.ActionType)))
        {
            this.volunteerTr1.Visible = true;
            this.volunteerTr2.Visible = true;


        }
        else 
        {

        }
        //else
        //{
        //    this.txtActName.ReadOnly = true;
        //    this.txtActDate.ReadOnly = true;
        //    this.txtActAddress.ReadOnly = true;

        //}
        //if (ACTION_TYPE.Equals(Convert.ToString(ViewState["ACTION_TYPE"])))
        //{
        //    bean.ActionResultId = Convert.ToInt32(id);
        //    bean = dao.LoadHappyPlanResultByResultId(bean);
        //}
        //    //普通活动
        //else 
        //{
        //    bean.ActionId = Convert.ToInt32(id);
        //    bean = dao.LoadHappyPlanResultByActionId(bean);

        //    if (bean == null)
        //    {

        //    }
        //    //查找普通活动小结
        //    bean.ActionResultId = Convert.ToInt32(id);
        //    bean = dao.LoadHappyPlanResultByResultId(bean);
           
        //    //新建的普通活动小结
        //    if (bean == null)
        //    {
              
        //    }

        //    //小结表中不存在时查找计划表
        //    if (bean == null)
        //    {
        //        bean = new HappyPlanResultBean();
        //        bean.ActionId = Convert.ToInt32(id);
        //        bean = dao.FindHappyPlan(bean);
        //    }
        //}





        if (bean == null)
        {
            ((Design_MasterPage)this.Master).InfoMessage =
                HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "E0203").ToString().Replace("{0}", "活动计划");
            return;
        }
        //btnDel.Enabled = true;
        // set data to page
        lblActId.Text = Convert.ToString(bean.ActionResultId);
        txtActName.Text = bean.ActionName;
        lstActType.SelectedValue = bean.ActionType;
        if (bean.BespokeDate != null)
        { txtActDate.Text = DateUtils.convertToString(bean.BespokeDate.Value); }
        txtActDateMemo.Text = bean.BespokeDateText;
        txtActAddress.Text = bean.ActionAddress;
        txtActObject.Text = bean.ActionObject;
        if (bean.ActionCount != null)
        { txtActCount.Text = Convert.ToString(bean.ActionCount); }
        txtActMainPsn.Text = bean.ResponsibilityId;
        txtActCoPsn1.Text = bean.CoadjutantId;
        txtActCoPsn2.Text = bean.Coadjutant2Id;
        txtActCoPsn3.Text = bean.Coadjutant3Id;
        txtActMainPsnName.Text = bean.RespPesonName;
        txtActCoPsn1Name.Text = bean.CoPeson1Name;
        txtActCoPsn2Name.Text = bean.CoPeson2Name;
        txtActCoPsn3Name.Text = bean.CoPeson3Name;

        if (ACTION_TYPE.Equals(Convert.ToString(ViewState["ACTION_TYPE"])))
        {
            this.txtServerNum.Text = bean.ServerNum.ToString();
            this.txtVolunteerNum.Text = bean.VolunteerNum.ToString();
            this.radServerType.SelectedValue = bean.ServerType.ToString();
            this.txtServerOther.Text = bean.ServerOther;
        }
        // fee
        if (bean.FeePropagandize != null)
        { txtFeePropagandize.Text = String.Format("{0:N}", bean.FeePropagandize); }
        if (bean.FeeManpower != null)
        { txtFeeManpower.Text = String.Format("{0:N}", bean.FeeManpower); }
        if (bean.FeeMaterial != null)
        { txtFeeMaterial.Text = String.Format("{0:N}", bean.FeeMaterial); }
        if (bean.FeeTraffic != null)
        { txtFeeTraffic.Text = String.Format("{0:N}", bean.FeeTraffic); }
        if (bean.FeeOther != null)
        { txtFeeOther.Text = String.Format("{0:N}", bean.FeeOther); }
        txtFeeTotal.Text = bean.Amount;

        // content
        this.txtContent.Text = bean.ActionContent;
        txtMemo2.Text = bean.ActionDocument;



    }

    // 取得审批权限
    private int getJobLevel()
    {
        SysUserManager manager = new SysUserManager(Context);
        SysUserBean sysUserBean = manager.getSysUserBean();
        MstSysUserBean mstSysUserBean =
            sysUserBean == null ? null : sysUserBean.getMstSysUserBean();
        MstEmployeeBean mstEmpBean =
            sysUserBean == null ? null : sysUserBean.getEmployeeBean();
        string loginId = mstSysUserBean == null ? "" : mstSysUserBean.SysUserId;
        string emplyId = mstSysUserBean == null ? "" : mstSysUserBean.EmployeeId;
        PersonEmployeeBean beanEmp = new PersonEmployeeBean();
        HappyPlanDao dao = new HappyPlanDao();
        beanEmp.EmployeeId = emplyId;
        beanEmp = dao.GetEmployeeJob(beanEmp);
        if (beanEmp == null || string.IsNullOrEmpty(beanEmp.JobLimit))
        { return 0; }
        return Convert.ToInt32(beanEmp.JobLimit);
    }

    // reset controls to page
    private void resetFormControls()
    {
        lblActId.Text = string.Empty;
        txtActName.Text = string.Empty;
        if (lstActType.Items.Count > 0) lstActType.SelectedIndex = 0;
        txtActDate.Text = string.Empty;
        txtActDateMemo.Text = string.Empty;
        txtActAddress.Text = string.Empty;
        txtActObject.Text = string.Empty;
        txtActCount.Text = string.Empty;
        txtActMainPsn.Text = string.Empty;
        txtActMainPsnName.Text = string.Empty;
        txtActCoPsn1.Text = string.Empty;
        txtActCoPsn1Name.Text = string.Empty;
        txtActCoPsn2.Text = string.Empty;
        txtActCoPsn2Name.Text = string.Empty;
        txtActCoPsn3.Text = string.Empty;
        txtActCoPsn3Name.Text = string.Empty;

        // fee        
        txtFeePropagandize.Text = string.Empty;
        txtFeeManpower.Text = string.Empty;
        txtFeeMaterial.Text = string.Empty;
        txtFeeTraffic.Text = string.Empty;
        txtFeeOther.Text = string.Empty;
        txtFeeTotal.Text = string.Empty;

        this.txtContent.Text = string.Empty;
        this.txtServerNum.Text = string.Empty;
        this.txtVolunteerNum.Text = string.Empty;
        this.radServerType.SelectedIndex = 0;
        this.txtServerOther.Text = string.Empty;


        // content
        //txtMemo1.Text = string.Empty;
        txtMemo2.Text = string.Empty;

        // auditing
        //if (lstAud1.Items.Count > 0) lstAud1.SelectedIndex = 0;
        //if (lstAud2.Items.Count > 0) lstAud2.SelectedIndex = 0;
        //txtAudMemo1.Text = string.Empty;
        //txtAudMemo2.Text = string.Empty;
    }

    // bind common catalog data 
    private void initPageControls()
    {
        HappyPlanDao dao = new HappyPlanDao();
        CommonDictionaryBean beanComDict = new CommonDictionaryBean();
        IList lstCat = null;

        // 活动分类
        log.Fatal("\n ***** get 活动分类 catalog *****");
        beanComDict.Catalog = "T_ACTION_ADVICE.ADVICE_TYPE";
        lstCat = dao.FindByCatalog(beanComDict);
        lstActType.Items.Clear();
        bindDataToListControl("lstActType", lstCat);

        // 审核状态
        //log.Fatal("\n ***** get 审核状态 catalog *****");
        //beanComDict.Catalog = "T_ACTION_ADVICE.DEPARTMENT_ADVICE";
        //lstCat = dao.FindByCatalog(beanComDict);
        //lstAud1.Items.Clear();
        //lstAud2.Items.Clear();
        //bindDataToListControl("lstAud1", lstCat);
        ////if (lstAud1.Items.Count > 0) lstAud1.Items.RemoveAt(0);
        //bindDataToListControl("lstAud2", lstCat);
        //if (lstAud2.Items.Count > 0) lstAud2.Items.RemoveAt(0);
    }

    // bind db data to selected controls
    private void bindDataToListControl(string ControlId, IList LstData)
    {
        if (LstData == null || LstData.Count == 0) return;

        foreach (CommonDictionaryBean bean in LstData)
        {
            if (this.Master.FindControl("ContentPlaceHolder1").FindControl(ControlId) is DropDownList)
            {
                ((DropDownList)this.Master.FindControl("ContentPlaceHolder1").FindControl(ControlId)).Items.Add(new ListItem(bean.Content, bean.DictNo.ToString()));
            }
            else if ((this.Master.FindControl("ContentPlaceHolder1").FindControl(ControlId) is CheckBoxList)
                || (this.Master.FindControl("ContentPlaceHolder1").FindControl(ControlId) is RadioButtonList))
            {
                ((ListControl)this.Master.FindControl("ContentPlaceHolder1").FindControl(ControlId)).Items.Add(new ListItem(bean.Content, bean.DictNo.ToString()));
            }
        }
    }


    protected void lstActType_SelectedIndexChanged(object sender, EventArgs e)
    {
        ViewState["ACTION_TYPE"] = (sender as DropDownList).SelectedValue;
        this.volunteerTr2.Visible = ACTION_TYPE.Equals((sender as DropDownList).SelectedValue);
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        ComValidateChecker vd = new ComValidateChecker();
        vd.CheckItems.Add(new CheckRequired(this.txtActionId.Text, new ComMessage("E0094", "活动编号")));
        vd.CheckItems.Add(new CheckLong(this.txtActionId.Text, new ComMessage("E0322", "活动编号")));
        if (!vd.DoValidator())
        {
            ((Design_MasterPage)this.Master).InfoMessage = vd.ErrorMessage;
            return;
        }


        HappyPlanDao dao = new HappyPlanDao();
        HappyPlanBean bean = new HappyPlanBean();
        bean.ActionId = Convert.ToInt32(this.txtActionId.Text);
        bean = dao.FindHappyPlan(bean);

        if (bean != null)
        {
            txtActName.Text = bean.ActionName;
            lstActType.SelectedValue = bean.ActionType;
            if (bean.BespokeDate != null)
            { txtActDate.Text = DateUtils.convertToString(bean.BespokeDate.Value); }
            txtActDateMemo.Text = bean.BespokeDateText;
            txtActAddress.Text = bean.ActionAddress;
            txtActObject.Text = bean.ActionObject;
            if (bean.ActionCount != null)
            { txtActCount.Text = Convert.ToString(bean.ActionCount); }
            txtActMainPsn.Text = bean.ResponsibilityId;
            txtActCoPsn1.Text = bean.CoadjutantId;
            txtActCoPsn2.Text = bean.Coadjutant2Id;
            txtActCoPsn3.Text = bean.Coadjutant3Id;
            txtActMainPsnName.Text = bean.RespPesonName;
            txtActCoPsn1Name.Text = bean.CoPeson1Name;
            txtActCoPsn2Name.Text = bean.CoPeson2Name;
            txtActCoPsn3Name.Text = bean.CoPeson3Name;

            ViewState["ACTION_TYPE"] = bean.ActionType;
            if (ACTION_TYPE.Equals(Convert.ToString(bean.ActionType)))
            {
                //this.txtServerNum.Text = bean.ServerNum.ToString();
                //this.txtVolunteerNum.Text = bean.VolunteerNum.ToString();
                //this.radServerType.SelectedValue = bean.ServerType.ToString();
                //this.txtServerOther.Text = bean.ServerOther;

                this.volunteerTr1.Visible = true;
                this.volunteerTr2.Visible = true;
            }
            else
            {
                this.volunteerTr1.Visible = false;
                this.volunteerTr2.Visible = false;
            }
            // fee
            if (bean.FeePropagandize != null)
            { txtFeePropagandize.Text = String.Format("{0:N}", bean.FeePropagandize); }
            if (bean.FeeManpower != null)
            { txtFeeManpower.Text = String.Format("{0:N}", bean.FeeManpower); }
            if (bean.FeeMaterial != null)
            { txtFeeMaterial.Text = String.Format("{0:N}", bean.FeeMaterial); }
            if (bean.FeeTraffic != null)
            { txtFeeTraffic.Text = String.Format("{0:N}", bean.FeeTraffic); }
            if (bean.FeeOther != null)
            { txtFeeOther.Text = String.Format("{0:N}", bean.FeeOther); }
            txtFeeTotal.Text = bean.Amount;

            // content
            this.txtContent.Text = bean.ActionContent;
            txtMemo2.Text = bean.ActionDocument;
        }
        else 
        {

            ((Design_MasterPage)this.Master).InfoMessage =
                   HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "I0048").ToString();
        }
        

    }
}
